#include "QueryPlanNode.h"

JoinNode::JoinNode(int inPipeIdL, int inPipeIdR, int outPipeId, CNF* cnf,
		Record* literal, Schema *schemaL, Schema *schemaR,
		Pipe *inPipeL, Pipe *inPipeR, Pipe *outPipe) : QueryPlanNode(join),
		inPipeIdL(inPipeIdL), inPipeIdR(inPipeIdR), outPipeId(outPipeId),
		cnf(cnf), literal(literal), schemaL(schemaL), schemaR(schemaR),
		inPipeL(inPipeL), inPipeR(inPipeR), outPipe(outPipe) {
}

void JoinNode::Print(){
	cout<<"********\n";
	cout<<"Join Operation\n";
	cout<<"Input pipe ID "<<inPipeIdL<<endl;
	cout<<"Input pipe ID "<<inPipeIdR<<endl;
	cout<<"Output pipe ID "<<outPipeId<<endl;
	cout<<"Output Schema:"<<endl;
	schemaL->Print();
	schemaR->Print();
	cout<<"Join CNF:\n";
	cnf->Print();
	cout<<"********\n";
}

void JoinNode::Execute(){
	J.Use_n_Pages(RUN_LENGTH);
	//J.Run(*inPipeL, *inPipeR, *outPipe, *cnf, *literal, *schemaL, *schemaR);
	J.Run(*inPipeL, *inPipeR, *outPipe, *cnf, *literal);
}

void JoinNode::Wait(){
	J.WaitUntilDone();
}

void JoinNode::Clean(){

}
